<template>
	<view>
		<view class="goods-section">
			<view class="g-header b-b">
				<text class="name">基本信息</text>
			</view>
			<!-- 商品列表 -->
			<view class="g-item">
				<view>
					<view class="okami">
						<view class="left">
							<u-avatar mode="square" size='160' bgColor='#b3b3b3' :src="user.avatar"></u-avatar>
						</view>
						<view class="right">
							<view class="top">
								<view class="title tui-flex-box">
									<text style="font-size: larger;">{{ detailed.user.name }}</text>
									<u-tag style="margin-left: 20rpx;" :text="detailed.user.sexAge"
										:type="detailed.user.type" shape="circle" size="mini" />
								</view>
							</view>

							<view style="color: #a7a8a9;padding-top: 20rpx;">UID：{{ detailed.user.id }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 金额明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">次数</text>
				<view class="cell-tip red">
					<tui-numberbox :value="order.number" :step="1" @change="change"></tui-numberbox>
				</view>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">单价</text>
				<text class="cell-tip">{{detailed.okami.price}} 币</text>
			</view>
			<view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">备注</text>
				<input class="desc" type="text" v-model="order.desc" placeholder="请填写备注信息"
					placeholder-class="placeholder" />
			</view>
		</view>

		<!-- 底部 -->
		<view class="footer">
			<view class="price-content">
				<text style="padding-right: 20rpx;">总额</text>
				<text class="price">{{order.totalPrice}}</text>
				<text class="price-tip">币</text>
			</view>
			<text class="submit" @click="submit">提交申请</text>
		</view>

	</view>
</template>

<script>
	import hallOkami from "@/components/hall_okami/hall_okami.vue"
	export default {
		data() {
			return {
				id: 0,
				order: {
					okamiId: '',
					number: 1,
					price: '40.00',
					desc: '',
					totalPrice: '40.00'
				},
				detailed: {
					user: {
						id: "654214",
						avatar: "http://img3.imgtn.bdimg.com/it/u=1150341365,1327279810&fm=26&gp=0.jpg",
						name: "名字可以有8个字", // 名字
						sexAge: "♀23", // 性别年龄
						type: "error",
						views: "254", // 浏览量
						orderVolume: "21", // 订单量
						score: "4.7",
						birthday: "2003-5-1",
						constellation: "水瓶座",
						region: "湖南 娄底 娄星区",
						signature: "签名二十个字签名二十签名二十个签名二十个",
						isFollow: false
					},
					okami: {
						price: '40',
						isServer: false,
						describe: "描述两百个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个描述五十个",
						gameName: "第五人格",
						gameRank: "一阶",
						requirement: ["可爱", "声音好听", "不无聊", "带飞"],
						imgList: [{
								src: 'https://gd3.alicdn.com/imgextra/i3/0/O1CN01IiyFQI1UGShoFKt1O_!!0-item_pic.jpg_400x400.jpg'
							},
							{
								src: 'https://gd3.alicdn.com/imgextra/i3/TB1RPFPPFXXXXcNXpXXXXXXXXXX_!!0-item_pic.jpg_400x400.jpg'
							},
							{
								src: 'https://gd2.alicdn.com/imgextra/i2/38832490/O1CN01IYq7gu1UGShvbEFnd_!!38832490.jpg_400x400.jpg'
							},
							{
								src: 'https://gd2.alicdn.com/imgextra/i2/38832490/O1CN01IYq7gu1UGShvbEFnd_!!38832490.jpg_400x400.jpg'
							}
						],
					}
				},
				user: {
					id: "654214",
					avatar: "http://img3.imgtn.bdimg.com/it/u=1150341365,1327279810&fm=26&gp=0.jpg",
					name: "名字可以有8个字", // 名字
					sexAge: "♀23", // 性别年龄
					type: "error",
					views: "254", // 浏览量
					orderVolume: "21", // 订单量
					score: "4.7",
					birthday: "2003-5-1",
					constellation: "水瓶座",
					region: "湖南 娄底 娄星区",
					signature: "签名二十个字签名二十签名二十个签名二十个"
				},
			}
		},
		onLoad(options) {
			//接收传值,id里面放的是标题，因为测试数据并没写id 
			let id = options.id;
			if (id) {
				console.debug(id);
				this.id = id;
			}

			let login_info = this.checkLogin();
			console.debug('查询是否登录' + login_info);
			if (login_info) {} else {
				uni.showToast({
					title: '请先登录',
					icon: 'none'
				});
			}

			uni.request({
				url: this.httpRoot + 'okami/details',
				method: 'GET',
				data: {
					id: this.id
				},

				success: res => {
					console.debug(res);
					console.debug(res.data);
					var code = 0;
					var data = {};
					var message = '';
					if ('code' in res.data) {
						code = res.data.code;
					}
					if ('message' in res.data) {
						message = res.data.message;
					}
					if ('data' in res.data) {
						data = res.data.data;
						// data = res.data.data.parseJSON(); //由JSON字符串转换为JSON对象
						// data = JSON.parse(res.data.data);
						console.debug('数据：');
						console.debug(data);
						if ('detailed' in data) {
							this.detailed = data.detailed;
							console.debug(data.detailed);

							this.order.totalPrice = 1 * this.detailed.okami.price;
						}
					} else {
						uni.showToast({
							title: '服务器错误',
							icon: 'none'
						});
					}
					if (message != '') {
						uni.showToast({
							title: message,
							icon: 'none'
						});
					}
				},
				fail: () => {
					uni.showModal({
						title: '请求数据失败'
					});
				},
				complete: () => {

				}
			});
		},
		methods: {
			change(e) {
				if (e.value > 0) {
					this.order.number = e.value;
					this.order.totalPrice = this.order.number * this.detailed.okami.price;
				}
			},
			submit() {
				let login_info = this.checkLogin();
				console.debug('查询是否登录' + login_info);
				if (login_info) {
					var token = login_info[0];
					console.debug('token:' + token);
					console.debug('Okami UID' + this.id)
					console.debug('数量' + this.order.number)
					console.debug('备注' + this.order.desc)

					let order;
					order = {
						ok_id: this.id,
						number: this.order.number,
						remarks: this.order.desc
					}

					uni.request({
						url: this.httpRoot + 'order/creat',
						method: 'POST',
						header: {
							"token": token
						},
						data: {
							order: order
						},
						success: res => {
							console.debug(res);
							console.debug(res.data);
							var code = 0;
							var data = {};
							var message = '';
							if ('code' in res.data) {
								code = res.data.code;
							}
							if ('message' in res.data) {
								message = res.data.message;
							}
							if ('data' in res.data) {
								data = res.data.data;
								// data = res.data.data.parseJSON(); //由JSON字符串转换为JSON对象
								// data = JSON.parse(res.data.data);
								console.debug('数据：');
								console.debug(data);
								if ('order_id' in data) {
									uni.showToast({
										title: '提交成功'
									});
									setTimeout(() => {
										uni.redirectTo({
											url: '../order_details/order_details?id=' + data.order_id
										});
									}, 2000);
								}
							} else {
								uni.showToast({
									title: '服务器错误',
									icon: 'none'
								});
							}
							if (message != '') {
								uni.showToast({
									title: message,
									icon: 'none'
								});
							}
						},
						fail: () => {
							uni.showModal({
								title: '请求数据失败'
							});
						},
						complete: () => {

						}
					});

				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					});
				}
			},
			getSexAge(item) {
				var str = "";
				if (item.sex == "男") {
					str += "♂";
				} else if (item.sex == "女") {
					str += "♀";
				}
				str += item.age.toString();
				return str;
			},
			getTypeBySex(item) {
				if (item.sex == "男") {
					return "primary";
				} else if (item.sex == "女") {
					return "error";
				}
				return "error";
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background-color: #f2f3f4;
	}


	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28upx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34upx;
			margin-right: 24upx;
		}

		.address {
			margin-top: 16upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

	.goods-section {
		margin-top: 16upx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50upx;
			height: 50upx;
			border-radius: 100px;
		}

		.name {
			font-size: 30upx;
			color: $font-color-base;
			margin-left: 24upx;
		}

		.g-item {
			display: flex;
			margin: 20upx 30upx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}

			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
			}

			.title {
				font-size: 30upx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26upx;
				color: $font-color-light;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 32upx;
				color: $font-color-dark;
				padding-top: 10upx;

				.price {
					margin-bottom: 4upx;
				}

				.number {
					font-size: 26upx;
					color: $font-color-base;
					margin-left: 20upx;
				}
			}

			.step-box {
				position: relative;
			}
		}
	}

	.yt-list {
		margin-top: 16upx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx 10upx 40upx;
		line-height: 70upx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 32upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-light;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}

			&.red {
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90upx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

	/* 支付列表 */
	.pay-list {
		padding-left: 40upx;
		margin-top: 16upx;
		background: #fff;

		.pay-item {
			display: flex;
			align-items: center;
			padding-right: 20upx;
			line-height: 1;
			height: 110upx;
			position: relative;
		}

		.icon-weixinzhifu {
			width: 80upx;
			font-size: 40upx;
			color: #6BCC03;
		}

		.icon-alipay {
			width: 80upx;
			font-size: 40upx;
			color: #06B4FD;
		}

		.icon-xuanzhong2 {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 40upx;
			color: $base-color;
		}

		.tit {
			font-size: 32upx;
			color: $font-color-dark;
			flex: 1;
		}
	}

	.footer {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90upx;
		justify-content: space-between;
		font-size: 30upx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0, 0, 0, .1);

		.price-content {
			padding-left: 30upx;
		}

		.price-tip {
			color: $base-color;
			margin-left: 8upx;
		}

		.price {
			font-size: 36upx;
			color: $base-color;
		}

		.submit {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 280upx;
			height: 100%;
			color: #fff;
			font-size: 32upx;
			background-color: $base-color;
		}
	}


	.tui-flex-box {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
		justify-content: flex-start;
		align-items: flex-start;
		margin-bottom: 26rpx;
	}

	.paly_tag {
		margin-left: 6rpx;
	}

	.okami {
		width: 100%;
		height: auto;
		background-color: #ffffff;
		display: flex;
		padding: 30rpx 20rpx 10rpx;
		border-radius: 20rpx;

		.left {
			padding: 0 10rpx;
			background-color: #FFFFFF; //rgb(94, 152, 225);
			text-align: center;
			font-size: 28rpx;
			color: #000000;
		}

		.right {
			padding: 10rpx 20rpx 0;
			font-size: 28rpx;

			.top {
				width: 100%;
				border-bottom: 2rpx dashed $u-border-color;

				.title {
					margin-right: 60rpx;
					line-height: 40rpx;
				}

				.bottom {
					// display: flex;
					margin-top: 20rpx;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 10rpx;
				}
			}

			.tips {
				width: 100%;
				line-height: 50rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.transpond {
					margin-right: 10rpx;
				}

				.explain {
					display: flex;
					align-items: center;
				}

				.money {
					color: #ff0000;
					padding-right: 10rpx;
					font-size: 36upx;
				}
			}
		}
	}
</style>
